package handle

import (
	"context"
	pb "week2zk-project/rpc/api/goods"
	"week2zk-project/rpc/internal/model"
)

// 定义空接口

type GoodsInfoService struct {
	pb.UnimplementedGoodsServiceServer
}

func (s *GoodsInfoService) CreateGoods(ctx context.Context, req *pb.CreateGoodsRequest) (*pb.CreateGoodsResponse, error) {
	g := model.Goods{
		GoodsTitle:  req.GoodsTitle,
		GoodsImg:    req.GoodsImg,
		GoodsPrice:  req.GoodsPrice,
		GoodsStock:  req.GoodsStock,
		SalesVolume: req.SalesVolume,
		Evaluate:    req.Evaluate,
	}
	err := g.Create()
	if err != nil {
		return &pb.CreateGoodsResponse{
			Code: 400,
			Msg:  "创建商品失败",
		}, err
	}
	return &pb.CreateGoodsResponse{
		Code:    200,
		Msg:     "创建商品成功",
		GoodsId: int64(g.ID),
	}, nil
}
